package com.origin.utils.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.TextView;

import com.origin.utils.R;

public class ErrorDialog extends Dialog {
    int dialogResult;
    Handler mHandler;


    public ErrorDialog(Activity context, String errorStr) {
        super(context);
        setOwnerActivity(context);
        onCreate();
        setCancelable(false);
        TextView errorTv = (TextView) findViewById(R.id.error_tv);
        errorTv.setText(errorStr);
    }

    public int getDialogResult() {
        return dialogResult;
    }

    public void setDialogResult(int dialogResult) {
        this.dialogResult = dialogResult;
    }

    /**
     * Called when the activity is first created.
     */

    public void onCreate() {
        setContentView(R.layout.dialog_error);

    }

    public void endDialog(int result) {
        dismiss();
        setDialogResult(result);
        Message m = mHandler.obtainMessage();
        mHandler.sendMessage(m);
    }

    public int showDialog() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message mesg) {
                // process incoming messages here
                //super.handleMessage(msg);
                throw new RuntimeException();
            }
        };
        super.show();
        try {
            Looper.getMainLooper().loop();
        } catch (RuntimeException e2) {
        }
        return dialogResult;
    }

}
